package com.dd.ms.starter.autoconfigure;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/10/20 11:11
 * @Description 类功能作用说明
 */
@Slf4j
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(MicroserviceProperties.class)
@ConditionalOnProperty(prefix = "dd.microservice.starter", name = "enabled", matchIfMissing = true)
public class MicroserviceAutoConfiguration {

    private final MicroserviceProperties properties;

    public MicroserviceAutoConfiguration(MicroserviceProperties properties) {
        log.info("=== MicroserviceAutoConfiguration 初始化 ===");
        log.info("配置属性: enabled={}, name={}", properties.isEnabled(), properties.getName());
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean
    public ServiceStatusChecker serviceStatusChecker() {
        log.info("=== 创建 ServiceStatusChecker Bean ===");
        return new ServiceStatusChecker(properties.getName());
    }
}